package com.egao.gzh.service;

import com.egao.common.core.damon.utils.HttpsUtils;
import net.sf.json.JSONObject;

/**
 * @author Damon
 * @create 2020-09-02 12:16
 */
public class GzhGetQRcode {

    /**
     * 得到生成二维码需要的ticket
     * @return
     */
    public String getQRcodeTicket() {
        GzhToken gt = new GzhToken();
        String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+ gt.getAccessToken();
        //生成临时字符串二维码
        String data = "{\"expire_seconds\": 2400, \"action_name\": \"QR_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"customerId=12;customerName=中盈\"}}}";
        String post = HttpsUtils.post(url, data);
        String ticket = JSONObject.fromObject(post).getString("ticket");
        return ticket;
    }

    public String getQrCode(){
        String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ getQRcodeTicket();
        return url;

    }
}
